package com.kedacom.freedomLabel.viewmodel.printer;

import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.OnLifecycleEvent;

import com.kedacom.freedomLabel.Options;
import com.kedacom.freedomLabel.base.BaseViewModel;
import com.kedacom.freedomLabel.base.BasicCache;
import com.kedacom.freedomLabel.model.annotation.PrinterSettingCategory;
import com.kedacom.freedomLabel.model.bean.Template;

/**
 * @author licheng
 * @since 2019/12/23 14:59
 */
public class PrinterSettingViewModel extends BaseViewModel {

    public void onSelectSettingItemClick(String type) {
        sendMessage(Options.MSG_SELECT_PRINTER_SETTING_ITEM, type);
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    public void prepareTemplate() {
        Template template = BasicCache.getInstance().getTemplate();
        sendMessage(Options.MSG_UPDATE_TEMPLATE, template);
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    public void prepareSelectPrinterSettingItem() {
        int gapIndex = BasicCache.getInstance().getPrinterItemIndex(
                Options.MSG_SELECT_ITEM + "_" + PrinterSettingCategory.GAP);
        sendMessage(Options.MSG_SELECT_ITEM + "_" + PrinterSettingCategory.GAP, gapIndex);

        int directionIndex = BasicCache.getInstance().getPrinterItemIndex(
                Options.MSG_SELECT_ITEM + "_" + PrinterSettingCategory.DIRECTION);
        sendMessage(Options.MSG_SELECT_ITEM + "_" + PrinterSettingCategory.DIRECTION, directionIndex);

        int densityIndex = BasicCache.getInstance().getPrinterItemIndex(
                Options.MSG_SELECT_ITEM + "_" + PrinterSettingCategory.DENSITY);
        sendMessage(Options.MSG_SELECT_ITEM + "_" + PrinterSettingCategory.DENSITY, densityIndex);

        int speedIndex = BasicCache.getInstance().getPrinterItemIndex(
                Options.MSG_SELECT_ITEM + "_" + PrinterSettingCategory.SPEED);
        sendMessage(Options.MSG_SELECT_ITEM + "_" + PrinterSettingCategory.SPEED, speedIndex);
    }
}